<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .bw {
            width: 550px;
            margin: 100px auto;
        }

        .msg {
            display: inline-block;
            font-size: 15px;
            color: darkolivegreen;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 25px;
        }

        /* 密码不满足条件 */
        .bw1 {
            color: red;
            background-image: url(images/wrong.png);
        }

        /* 密码满足条件 */
        .bw2 {
            color: green;
            background-image: url(images/right.png);
        }
    </style>
</head>

<body>
    <div class="bw">
        <input type="password" class="passwd">
        <p class="msg">请输入6-16位数的密码</p>
    </div>

    <script>
        const inputObj = document.querySelector("input");
        const pObj = document.querySelector("p");

        inputObj.onblur = function () {
            if (inputObj.value.length < 6 || inputObj.value.length > 16) {
                pObj.className = "msg bw1";//当需要在前一个样式的基础上进行操作时，并列写className，这样可以起到覆盖的效果
                pObj.innerText = "输入的密码不满足要求格式";
            } else {
                pObj.className = "msg bw2";
                pObj.innerText = "输入的密码满足要求格式";
            }
        }
    </script>
</body>

</html>